package com.example.shopping1902.me;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.shopping1902.R;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.List;

public class LocalImageAdapter extends BaseAdapter {
    Context context;
    List<String>list;

    public LocalImageAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount(){
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VH vh = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_localimg,null);
            vh = new VH(convertView);
            convertView.setTag(vh);
        }else {
            vh = (VH) convertView.getTag();
        }
        String path = list.get(position);//得到地址
        File file = new File(path);
        Picasso.with(context).load(file).into(vh.iv);
        return convertView;
    }
    class VH{
        ImageView iv;
        public VH(View v){
            iv = v.findViewById(R.id.item_localimg_iv);
        }
    }
}
